package multiThreadTest.nucleicacidtest;

import java.util.ArrayList;

public class HumanTraffic extends Thread{
    private int cycleTime=100;
    private int addMaxTime=100;
    private ArrayList<NucleicAcidDetectionPoint> pointList=new ArrayList<NucleicAcidDetectionPoint>();

    public HumanTraffic(int cycleTime,int addMaxTime) {
        this.cycleTime = cycleTime;
        this.addMaxTime=addMaxTime;
    }

    @Override
    public void run() {
        int shortestOneId=1;
        int shortestQueue;
        while (true){
            try {
                Thread.sleep(cycleTime+(int)(Math.random()*addMaxTime));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            shortestQueue=Integer.MAX_VALUE;
            for (int i = 0; i < pointList.size(); i++) {
                if(pointList.get(i).getQueueSize()<shortestQueue){
                    shortestOneId=i;
                    shortestQueue=pointList.get(i).getQueueSize();
                }
            }
            pointList.get(shortestOneId).lengthenQueueSize(1);
        }
    }
    public HumanTraffic addPoint(NucleicAcidDetectionPoint p){
        pointList.add(p);
        return this;
    }
}
